﻿function AddToCar(productId) {

    var isValid = true;
    var optional = [];
    var count = parseInt($.trim($(":text[name='quantity']").val()));
    count = isNaN(count) ? 1 : count;
    count = count > 0 ? count : 1;
    $(".sameProduct").each(function (i, n) {
        if ($(n).find("dd a.cur").length != 1) {
            alert("请选择:" + $(n).find("dt span").text());
            isValid = false;
            return isValid;
        };
        optional[i] = $(n).find("dd a.cur").attr("accesskey");
    });
    if (!isValid)
        return false;
    // 加入到购物车
    $.post(window.pv_addToCar_url, { ProductId: productId, count: count, optional: optional, rnd: Math.random() }, function (result) {
        result = $(result);
        result.dialog({ width: 500, modal: true, closeText: "×", close: function () { $(this).dialog("destroy"); $(":text[name='quantity']").val(1) } });
        window.CloseDialog = function () { result.dialog("close") }
    });


}